const { contextBridge, ipcRenderer } = require('electron')
const fs = require('fs')

// 暴露安全的API到渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
  // 文件操作
  readFile: (filePath) => {
    return fs.promises.readFileSync(filePath, 'utf8')
  },
  writeFile: (filePath, data) => {
    return fs.promises.writeFileSync(filePath, data)
  },
  // 进程通信
  sendMessage: (channel, data) => {
    ipcRenderer.send(channel, data)
  },
  onMessage: (channel, callback) => {
    ipcRenderer.on(channel, callback)
  }
})